package com.lipaluma.test.db.internal.assertions;

import static org.junit.Assert.assertEquals;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.commons.lang.BooleanUtils;

/**
 * test a boolean column
 * @author Mario
 */
class BooleanColumn extends Column<Boolean> {

	private BooleanColumn(Builder builder) {
		super(builder);
	}

	@Override
	public void assertValue(ResultSet rs) throws SQLException {
		if(name == null)
			assertEquals(getErrorMessageOnIndexColumn(), expectedValue.booleanValue(), rs.getBoolean(index));
		else
			assertEquals(getErrorMessageOnNamedColumn(), expectedValue.booleanValue(), rs.getBoolean(name));
	}
	
	public static BooleanColumn.Builder builder(String request) {
		return new Builder(request);
	}

	public static class Builder extends Column.Builder<Boolean>  {

		public Builder(String request) {
			super(request);
		}

		@Override
		public BooleanColumn.Builder withExpectedValue(String expected) {
			this.expectedValue = BooleanUtils.toBoolean(expectedValue);
			return this;
		}

		@Override
		public BooleanColumn build() {
			return new BooleanColumn(this);
		}

	}
}
